﻿namespace Exporter.Exporters.Implementations
{
    using System.IO;
    using System.Xml.Linq;
    using MoviesDataBase;

    /// <summary>
    /// The XML exporter.
    /// </summary>
    public class XmlExporter : IFileExporter
    {
        #region IFileExplorter Membres

        /// <summary>
        /// Exports the specified fil name.
        /// </summary>
        /// <param name="filName">Name of the fil.</param>
        /// <param name="movies">The movies.</param>
        public void Export(string filName, System.Collections.Generic.IEnumerable<MoviesDataBase.Movie> movies)
        {
            XDocument document = new XDocument();
            XElement root = new XElement("Films");

            foreach (Movie movie in movies)
            {
                XElement element = new XElement("Film");
                element.Add(new XElement("Title", movie.Title));
                element.Add(new XElement("Synopsis", movie.Synopsis));
                root.Add(element);
            }

            document.Add(root);
            document.Save(new FileStream(filName, FileMode.OpenOrCreate));
        }

        #endregion
    }
}
